package com.pig4cloud.pig.common.core.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author mobain
 * @date 2023/03/06
 */
@Getter
@AllArgsConstructor
public enum FieldType {
	INPUT("input", "输入框", "VARCHAR(255) NOT NULL DEFAULT ''","ElInput"),
	TEXTAREA("textarea", "多行输入框", "TEXT NOT NULL DEFAULT ''","ElInput"),
	PASSWORD("password", "密码输入框", "VARCHAR(255) NOT NULL DEFAULT ''","ElInput"),
	INPUT_NUMBER("inputNumber", "计数器", "INT NOT NULL DEFAULT '0'","ElInput"),
	RADIO("radio", "单选框", "VARCHAR(255) NOT NULL DEFAULT ''","ElInput"),
	CHECKBOX("checkbox", "多选框", "VARCHAR(255) NOT NULL DEFAULT ''","ElInput"),
	SELECT("select", "选择器", "VARCHAR(255) NOT NULL DEFAULT ''","ElInput"),
	SWITCH("switch", "开关", "TINYINT(1) NOT NULL DEFAULT '0'","ElInput"),
	RATE("rate", "评分", "INT NOT NULL DEFAULT '0'","ElInput"),
	TIME_PICKER("timePicker", "时间", "TIME","ElInput"),
	// 使用 JSON 表示时间区间
	TIME_RANGE("timeRange", "时间区间", "JSON","ElInput"),
	SLIDER("slider", "滑块", "INT NOT NULL DEFAULT '0'","ElInput"),
	DATE_PICKER("datePicker", "日期", "DATE","ElInput"),
	// 使用 JSON 表示时间区间
	DATE_RANGE("dateRange", "日期区间", "JSON","ElInput"),
	COLOR_PICKER("colorPicker", "颜色选择器", "VARCHAR(7) NOT NULL DEFAULT ''","ElInput"),
	CASCADER("cascader", "级联选择器", "VARCHAR(255) NOT NULL DEFAULT ''","ElInput"),
	UPLOAD("upload", "上传", "VARCHAR(255) NOT NULL DEFAULT ''","ElInput"),
	EL_TRANSFER("elTransfer", "穿梭框", "VARCHAR(255) NOT NULL DEFAULT ''","ElInput"),
	TREE("tree", "树形控件", "VARCHAR(255) NOT NULL DEFAULT ''","ElInput"),
	EL_TREE_SELECT("elTreeSelect", "树形选择", "VARCHAR(255) NOT NULL DEFAULT ''","ElInput"),
	FC_EDITOR("fcEditor", "富文本框", "TEXT","ElInput"),
	GROUP("group", "子表单", "JSON","ElInput");

	private final String value;
	private final String label;
	private final String type;
	private final String elType;

	private static final Map<String, FieldType> FIELD_TYPE_MAP = new HashMap<>();

	static {
		for (FieldType fieldType : FieldType.values()) {
			FIELD_TYPE_MAP.put(fieldType.getValue(), fieldType);
		}
	}

	public static FieldType getByValue(String value) {
		FieldType fieldType = FIELD_TYPE_MAP.get(value);
		if (fieldType == null) {
			return INPUT;
		}
		return fieldType;
	}
}
